package com.sheng.center.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.sheng.center.entity.Repair;
import com.sheng.center.service.RepairService;

public class RepairAction extends ActionSupport implements ModelDriven<Repair>{

	protected String forwardView;
	protected static final String ADD_JSP = "/WEB-INF/page/Repair_add.jsp";
	protected static final String EDIT_JSP = "/WEB-INF/page/Repair_edit.jsp";
	protected static final String LIST_JSP = "/WEB-INF/page/Repair_list.jsp";
    private Repair repair = new Repair();
    private List<Repair> list;
	private RepairService repairService;
	@Override
	public Repair getModel() {
		return repair;
	}
	
	
	/**
	 * 
	 * @Title: openAdd、openEdit
	 * @Description: 拦截动作打开对应页面
	 * @param @return 参数
	 * @return String 返回类型
	 * @author huangshengjun 1532950421@qq.com
	 * @date 2019年12月10日 下午8:36:29 
	 * @throws
	 */
	public String openAdd(){
		setForwardView(ADD_JSP);
		return SUCCESS;
	}
	public String openEdit() {
		repair = repairService.findById(repair);
		setForwardView(EDIT_JSP);
		return SUCCESS;
	}
	
	/**
	 * 
	 * @Title: 
	 * @Description: list列表，add添加，edit修改，delete删除
	 * @param @return 参数
	 * @return String 返回类型
	 * @author huangshengjun 1532950421@qq.com
	 * @date 2019年12月10日 下午8:37:20 
	 * @throws
	 */
	public String list() {
		list = repairService.findAllList(repair);
		setForwardView(LIST_JSP);
		return SUCCESS;
	}
	
	public String add() {
		repairService.add(repair);
		return list();
	}
	
	public String edit() {
		repairService.edit(repair);
		return list();
	}
	/**
	 * 
	 * @Title: delete
	 * @Description: 根据id查询这条信息并赋值，然后在daoImpl进行删除操作
	 * @param @return 参数
	 * @return String 返回类型
	 * @author huangshengjun 1532950421@qq.com
	 * @date 2019年12月11日 下午5:14:45 
	 * @throws
	 */
	public String delete() {
		repair = repairService.findById(repair);
		repairService.delete(repair);
		return list();
	}


	public String getForwardView() {
		return forwardView;
	}


	public void setForwardView(String forwardView) {
		this.forwardView = forwardView;
	}


	public Repair getRepair() {
		return repair;
	}


	public void setRepair(Repair repair) {
		this.repair = repair;
	}


	public List<Repair> getList() {
		return list;
	}


	public void setList(List<Repair> list) {
		this.list = list;
	}


	public RepairService getRepairService() {
		return repairService;
	}


	public void setRepairService(RepairService repairService) {
		this.repairService = repairService;
	}

}
